﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAccessLogic;

namespace BusinessLogic
{
    public class Phone : Table
    {
        #region Fields
        private PhoneType _phoneType;
        private string _number;
        private string _ext;
        private bool _isPrimary;
        private bool _isActive;
        #endregion

        #region Methods
        public static Phone GetPrimaryByConstituentID(Guid constituentID)
        {
            return DataAccess.Phone_DA.GetPrimaryByConstituentID(constituentID);
        }

        public static Phone GetByConstituentID(Guid constituentID)
        {
            return DataAccess.Phone_DA.GetByConstituentID(constituentID);
        }

        public static List<Phone> GetAllByConstituentID(Guid constituentID)
        {
            return DataAccess.Phone_DA.GetAllByConstituentID(constituentID);
        }
        #endregion

        #region Properties
        [SQLParameter(ColumnName = "ISACTIVE", SQLDoWhat = SQLDoWhatEnum.Get)]
        public bool IsActive
        {
            get
            {
                return _isActive;
            }
            set
            {
                _isActive = value;
            }
        }

        [SQLParameter(ColumnName = "ISPRIMARY", SQLDoWhat = SQLDoWhatEnum.Get)]
        public bool IsPrimary
        {
            get
            {
                return _isPrimary;
            }
            set
            {
                _isPrimary = value;
            }
        }
                
        public PhoneType PhoneType
        {
            get
            {
                return _phoneType;
            }
            set
            {
                _phoneType = value;
            }
        }

        [SQLParameter(ColumnName = "NUMBER", SQLDoWhat = SQLDoWhatEnum.Get)]
        public string Number
        {
            get
            {
                return _number;
            }
            set
            {
                _number = value;
            }
        }

        [SQLParameter(ColumnName = "EXTENSION", SQLDoWhat = SQLDoWhatEnum.Get)]
        public string Extension
        {
            get
            {
                return _ext;
            }
            set
            {
                _ext = value;
            }
        }

        public string NumberWithExtension
        {
            get 
            {
                if(string.IsNullOrWhiteSpace(_number))
                {
                    return string.Empty;
                }
                else
                {
                    if(!string.IsNullOrWhiteSpace(_ext))
                    {
                        return string.Concat(_number + " ext. " + _ext);
                    }
                    else
                    {
                        return _number;
                    }
                }
            }
        }
        #endregion


        public override DatabaseInteractionDescriptor TableInteractionDescription()
        {
            DatabaseInteractionDescriptor desc = new DatabaseInteractionDescriptor();
            desc.CreateStoredProcedure = StoredProcedures.USP_PHONE_CREATE;
            return desc;
        }
    }
}